home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 10 / FM Towns Free Software Collection 10.iso / ms_dos / tool / fapxtool / src / txl / txllog3.c < prev    next >
C/C++ Source or Header  |  1995-02-11  |  11KB  |  478 lines

  1. /***************
  2. *
  3. * g:\exe\txl\src\txllog2.c
  4. */
  5. #include "txl.h"
  6.  
  7.  
  8. #define BYTE(x) *((unsigned char *)(x))
  9. #define BIT_CHK(x,f) ((int)(BYTE(x+((f)>>3)) >> 7-((f) & 0x07)) & 1)
  10.  
  11. void get_forum(int type)
  12. {
  13.     char *dmyptr;
  14.  
  15.     log_pname[0] = NUL;
  16.     if (type == 1) {
  17.         dmyptr = log_bufptr - 49;
  18.         while (*dmyptr > ' ') {
  19.             dmyptr--;
  20.         }
  21.         if (strncmp("<フォーラム体験&質問コーナー>", dmyptr+1, 32)) {
  22.             sscanf(dmyptr, "%16s", log_fname);
  23.         }
  24.         else {
  25.             strcpy(log_fname ,"BEGIN");
  26.         }
  27.     }
  28.     if (type == 2) {
  29.         dmyptr = log_bufptr + 1;
  30.         sscanf(dmyptr, "%16s LIB:%[0-9]", log_fname, log_libstr);
  31.     }
  32. }
  33. void get_libno(int type)
  34. {
  35.     char *dmyptr;
  36.  
  37.     if ((type == 1) || (type == 2)) {
  38.         dmyptr = log_bufptr + 1;
  39.     }
  40.     sscanf(dmyptr, "%[0-9]", log_libstr);
  41. }
  42.  
  43. void get_titlestr()
  44. {
  45.     char *tmp;
  46.     char *env;
  47.     int i, ktype = CT_ANK;
  48.     int r1, r2, r3, r = 0, end = 1;
  49.  
  50.     tmp = log_bufptr;
  51.  
  52. /* 暫定 */
  53.     while (end) {
  54.         end = 0;
  55.         while (r1 = matchstr("re:", tmp)) {
  56.             end = 1;
  57.             tmp += 3;
  58.             r += 1;
  59.         }
  60.         while (r2 = matchstr("re$%:", tmp)) {
  61.             end = 1;
  62.             if (*(tmp + 3) > '0') {
  63.                 r += *(tmp + 3) - '0';
  64.             }
  65.             tmp += 5;
  66.         }
  67.         while (r3 = matchstr("re$%%:", tmp)) {
  68.             end = 1;
  69.             r += atoi(tmp + 3);
  70.             tmp += 6;
  71.         }
  72.         while (r3 = matchstr("re$%%%:", tmp)) {
  73.             end = 1;
  74.             r += atoi(tmp + 3);
  75.             tmp += 7;
  76.         }
  77.     }
  78.  
  79.     end = 1;
  80.     if ((env = getenv("TXLRES")) != NULL) {
  81.         if (matchstr("re$'%'d:", env) && r) {
  82.             end = 0;
  83.             sprintf(log_titlestr, env, r+1);
  84.         }
  85.     }
  86.     if (end) {
  87.         if (strncmp(tmp, log_resstr, strlen(log_resstr))) {
  88.             strcpy(log_titlestr, log_resstr);
  89.         }
  90.     }
  91.     strncat(log_titlestr, tmp, 41 - strlen(log_titlestr));
  92.  
  93.     tmp = strchr(log_titlestr, 0x0d);
  94.     if (tmp != NULL) {
  95.         *tmp = NUL;
  96.     }
  97.     else {
  98.         if (strlen(log_titlestr) > 40) {
  99. /*            *(jstradv(log_titlestr, btom(log_titlestr, 38))) = NUL; */
  100.             for ( i = 0; i < 41; i++) {
  101.                 if (*(log_titlestr + i) == NUL) {
  102.                     break;
  103.                 }
  104.                 ktype = chkctype(*(log_titlestr+i), ktype);
  105.             }
  106.             if (i > 40) {
  107.                 if (ktype != CT_KJ2) {
  108.                     *(log_titlestr+i-1) = NUL;
  109.                 }
  110.                 else {
  111.                     *(log_titlestr+i-2) = NUL;
  112.                 }
  113.             }
  114.         }
  115.     }
  116.  
  117. }
  118.  
  119. void del_tailspace(char *str, int len)
  120. {
  121.     int i;
  122.     for (i = len; i > 0; i--) {
  123.         if (*(str + i) == 0x20) {
  124.             *(str + i) = NUL;
  125.         }
  126.         else if ((*(str + i) == 0x40) && 
  127.                 (*(str + i - 1) == 0x81)) { /* 全角スペース    */
  128.             i--;
  129.             *(str + i) = NUL;
  130.         }
  131.         else {
  132.             break;
  133.         }
  134.     }
  135. }
  136.  
  137. void meschk(int style)
  138. {
  139.     if (style == 3) {
  140.         sscanf(log_bufptr, "%[0-9]", log_reply);
  141.         log_bufptr += 10;
  142.         strncpy(log_resp, log_bufptr, 8);
  143.         strncpy(log_rhandle, log_bufptr + 10, 16);
  144.         del_tailspace(log_rhandle, 15);
  145. #if 0
  146.         for (i = 15; i > 0; i--) {
  147.             if (*(log_rhandle + i) == 0x20) {
  148.                 *(log_rhandle + i) = NUL;
  149.             }
  150.             else if ((*(log_rhandle + i) == 0x40) && 
  151.                     (*(log_rhandle + i - 1) == 0x81)) { /* 全角スペース    */
  152.                 i--;
  153.                 *(log_rhandle + i) = NUL;
  154.             }
  155.             else {
  156.                 break;
  157.             }
  158.         }
  159. #endif
  160.         log_bufptr += 28;
  161.         get_titlestr();
  162.         if ((log_bufptr = strchr(log_bufptr, 0x0a)) == NULL) {
  163.             fprintf(fpmes, "Error:find EOF before title+1 line");
  164.             Exit(1);
  165.         }
  166.         log_bufptr += 2;
  167.         sscanf(log_bufptr, "%2d", &log_mesno);
  168.     }
  169.     else if (style == 2) {
  170.         log_bufptr += 2;
  171.         sscanf(log_bufptr, "%s  MES(%d)", log_fname, &log_mesno);
  172.         if (log_mesno == 0) {
  173.             sscanf(log_bufptr, "MES(%d)", &log_mesno);
  174.         }
  175.         *log_reply = NUL;
  176.         *log_titlestr = NUL;
  177.     }
  178.     else if (style == 1) {
  179.         sscanf(log_bufptr, "%2d", &log_mesno);
  180.         *log_reply = NUL;
  181.         *log_titlestr = NUL;
  182.     }
  183.     else if (style == 8) {
  184.         sscanf(log_bufptr, "%[0-9]", log_reply);
  185.         log_bufptr += 12;
  186.         strncpy(log_resp, log_bufptr, 8);
  187.         strncpy(log_rhandle, log_bufptr + 10, 16);
  188.         del_tailspace(log_rhandle, 15);
  189. #if 0
  190.         for (i = 15; i > 0; i--) {
  191.             if (*(log_rhandle + i) == 0x20) {
  192.                 *(log_rhandle + i) = NUL;
  193.             }
  194.             else if ((*(log_rhandle + i) == 0x40) && 
  195.                     (*(log_rhandle + i - 1) == 0x81)) { /* 全角スペース    */
  196.                 i--;
  197.                 *(log_rhandle + i) = NUL;
  198.             }
  199.             else {
  200.                 break;
  201.             }
  202.         }
  203. #endif
  204.         log_bufptr += 27;
  205.         get_titlestr();
  206.         if ((log_bufptr = strchr(log_bufptr, 0x0a)) == NULL) {
  207.             fprintf(fpmes, "Error:find EOF before title+1 line");
  208.             Exit(1);
  209.         }
  210.         log_bufptr += 2;
  211.         sscanf(log_bufptr, "%2d", &log_mesno);
  212.     }
  213.     if (log_pname[0] == NUL) {
  214.         fprintf(fpmes, "forum=%s;mes=%d;reply=%s;resp=%s;handle=%s;title=%s\n"
  215.             , log_fname, log_mesno, log_reply, log_resp, log_rhandle,
  216.                 log_titlestr);
  217.     }
  218.     else {
  219.         fprintf(fpmes, "patio=%s;mes=%d;reply=%s;resp=%s;handle=%s;title=%s\n"
  220.             , log_pname, log_mesno, log_reply, log_resp, log_rhandle,
  221.                 log_titlestr);
  222.     }
  223.  
  224. }
  225.  
  226. char *setdataexp(char kind)
  227. {
  228.     static char expbuf[4];
  229.  
  230.     switch (kind) {
  231.     case 'B':
  232.         strcpy(expbuf, "LZH");
  233.         break;
  234.     case 'T':
  235.         strcpy(expbuf, "ISH");
  236.         break;
  237.     case 'N':
  238.         strcpy(expbuf, "NPB");
  239.         break;
  240.     default:
  241.         strcpy(expbuf, "DAT");
  242.     }
  243.     return (expbuf);
  244. }
  245.  
  246. void get_downname(void)
  247. {
  248.     int i=0, j=0, type=CT_ANK, dmy=0;
  249.     char *tmp = log_bufptr;
  250.  
  251.     if (*tmp == '[') {
  252.         while ((*tmp != ']') && (*tmp != '\n')) tmp++;
  253.         if (*tmp == ']') tmp++;
  254.     }
  255.     for (i = 0; ((j < 8) && (*(tmp + i) != '.') &&
  256.             (*(tmp + i) != '\n')); i++) {
  257.         if (BIT_CHK(filechr, *(tmp + i)) ||
  258.                 ((type = chkctype(*(tmp + i), type)) != CT_ANK)) {
  259.             *(log_downname + j) = *(tmp + i);
  260.             j++;
  261.         }
  262.     }
  263.     if (*(tmp+i) == '.') {
  264.         *(log_downname+j) = '.';
  265.         j++;
  266.         tmp += i;
  267.         for (i = 1; (*(tmp + i) != '.') &&
  268.                 (*(tmp+i)!='\n'); i++) {
  269.             if (i == 1) {
  270.                 while (*(tmp + i) == ' ') {
  271.                     dmy++;
  272.                     i++;
  273.                 }
  274.             }
  275.             if (BIT_CHK(filechr, *(tmp+i)) ||
  276.                     ((type = chkctype((*tmp + i), type)) != CT_ANK)) {
  277.                 *(log_downname + j) = *(tmp + i);
  278.                 j++;
  279.             }
  280.             if ((i - dmy) >= 3) {
  281.                 break;
  282.             }
  283.         }
  284.     }
  285.  
  286.     if (*log_downname == 'n') {
  287.         *log_downname = 'N';
  288.     }
  289. }
  290.  
  291. void dlibchk(int style)
  292. {
  293. /*
  294.  250  PFG02442 92/04/05   25408   25 B TXF136E .EXE テキストファイル フォーマッタ Ver1.36e
  295. */
  296.     char exchr = NUL;
  297.     char *tmpptr;
  298.  
  299.     if (style == 5) { /* for 週間FTOWNS/週間FYUI */
  300.         log_bufptr += 3;
  301.         sscanf(log_bufptr, "%4d", &log_downno);
  302.         log_bufptr += 4;
  303.     }
  304.     else if (style == 4) {
  305.         sscanf(log_bufptr, "%4d", &log_downno);
  306.         strncpy(log_resp, log_bufptr + 6, 8);
  307.         log_resp[8] = NUL;
  308.  
  309.         exchr = *(log_bufptr+37);
  310.         log_bufptr += 39;
  311.     }
  312.     else if ((style == 19) || (style == 20)) {
  313.         log_bufptr += style - 18;
  314.         sscanf(log_bufptr, "%4d", &log_downno);
  315.         strncpy(log_resp, log_bufptr + 6, 8);
  316.         log_resp[8] = NUL;
  317.         exchr = *(log_bufptr+32);
  318.         log_bufptr += 34;
  319.     }
  320.  
  321.     get_downname();
  322.  
  323.     strcpy(log_docfile, log_downname);
  324.     if (strchr(log_docfile, '.')) {
  325.         strcpy(strchr(log_docfile, '.'), ".GGG");
  326.     }
  327.     else {
  328.         if (sprintf(log_downname, "LIB%d_%d.%s",
  329.             atoi(log_libstr), log_downno, setdataexp(exchr)) > 12) {
  330.             sprintf(log_downname, "%d_%d.%s",atoi(log_libstr), log_downno,
  331.                 setdataexp(exchr));
  332.             sprintf(log_docfile, "%d_%d.GGG",atoi(log_libstr), log_downno);
  333.         }
  334.         else {
  335.             sprintf(log_docfile, "LIB%d_%d.GGG",atoi(log_libstr), log_downno);
  336.         }
  337.  
  338.     }
  339.     if (style == 5) { /* for 週間FTOWNS/週間FYUI */
  340.         if ((tmpptr = strstr(log_bufptr, "掲載者-")) != NULL) {
  341.             strncpy(log_resp, tmpptr+8, 8);
  342.             log_resp[8] = NUL;
  343.         }
  344.     }
  345.     fprintf(fpmes, "forum=%s;libno=%s;datano=%d;resp=%s;docfile=%s;datafile=%s;\n"
  346.     ,log_fname, log_libstr, log_downno, log_resp, log_docfile, log_downname);
  347.  
  348. }
  349.  
  350. void get_forum_overrun(void)
  351. {
  352.     int cline = 0;
  353.     char *pstr;
  354.  
  355.     for (pstr = sfstr[0]; *pstr != NUL; log_bufptr++) {
  356.         if ((*pstr == *log_bufptr) || (*pstr == '*')) {
  357.             pstr++;
  358.         }
  359.         else {
  360.             pstr = sfstr[0];
  361.         }
  362.         if (*log_bufptr == 0x0a) {
  363.             cline++;
  364.             if (cline > 100) break;
  365.         }
  366.     }
  367.     if (*pstr==NUL) get_forum(1);
  368. }
  369.  
  370. void ffsutopchk(int style)
  371. {
  372. /*
  373. 09/08 [FMR]      INT12HFM.LZH SCAN/CLEANをFMで動かすTSR   SDI00618  (#5-26)
  374. */
  375.     int lib;
  376.  
  377.     log_bufptr += 17;
  378.     get_downname();
  379.     strcpy(log_docfile, log_downname);
  380.     if (strchr(log_docfile, '.')) {
  381.         strcpy(strchr(log_docfile, '.'), ".GGG");
  382.     }
  383.     log_bufptr += 41;
  384.     strncpy(log_resp, log_bufptr, 8);
  385.     log_resp[8] = NUL;
  386.     log_bufptr += 9;
  387.     if (*(log_bufptr+1) == '#') {
  388.         sscanf(log_bufptr, "(#%d-%d)", &lib, &log_downno);
  389.     }
  390.     else {
  391.         sscanf(log_bufptr, "(%d-%d)", &lib, &log_downno);
  392.     }
  393.  
  394. #if 0
  395.     /* 複数フォーラムの可能性がある場合 */
  396.     get_forum_overrun();
  397.  
  398.     fprintf(fpmes, "forum=%s;libno=%d;datano=%d;resp=%s;docfile=%s;datafile=%s;\n"
  399.         ,log_fname, lib, log_downno, log_resp, log_docfile, log_downname);
  400. #else
  401.     fprintf(fpmes, "forum=FFSU;libno=%d;datano=%d;resp=%s;docfile=%s;datafile=%s;\n"
  402.         ,lib, log_downno, log_resp, log_docfile, log_downname);
  403. #endif
  404. }
  405.  
  406. #if 0
  407. void ffmtopchk(int style)
  408. {
  409. /*
  410. 12/12[TOWNS] ぼむぼむ                 (DL 5-433)
  411. */
  412.     int i, lib, len;
  413.     char *tmpptr, target[16], str[4]="(DL";
  414.  
  415.     tmpptr = str;
  416.     for (i = 0; i < 80; i++) {
  417.         if (*log_bufptr != *tmpptr) {
  418.             tmpptr = str;
  419.             log_bufptr++;
  420.             if (*log_bufptr == 0x0a) {
  421.                 break;
  422.             }
  423.         }
  424.         else {
  425.             tmpptr++;
  426.             log_bufptr++;
  427.             if (*tmpptr == NUL) break;
  428.         }
  429.     }
  430.     if (*tmpptr == NUL) {
  431.         sscanf(log_bufptr + 1, "%2d-%4d", &lib, &log_downno);
  432.         len = sprintf(target, "DL%d_%d.lzh", lib, log_downno);
  433.         strcpy(log_downname, (target + (len > 12 ? 2 : 0)));
  434.         strcpy(log_docfile, log_downname);
  435.         strcpy(strchr(log_docfile, '.'), ".GGG");
  436.     }
  437.     else {
  438.         fprintf(fpmes, "Error:Fatal System Error,cannot continue.\n");
  439.         Exit(1);
  440.     }
  441.  
  442.     get_forum_overrun();
  443.  
  444.     fprintf(fpmes, "forum=%s;libno=%d;datano=%d;resp=;docfile=%s;datafile=%s;\n"
  445.         ,log_fname, lib, log_downno, log_docfile, log_downname);
  446. }
  447. #endif
  448.  
  449. void fravtopchk()
  450. {
  451. /*
  452. 08/31 Tue DL04 #349 ぴー              祝! FRAV
  453. 09/08 DL05 #142 しゅばるつしると  TIFF:『攻撃隊軌道待機』
  454. */
  455.     int lib, len;
  456.     char target[16];
  457.  
  458.     log_bufptr += 8;
  459.     sscanf(log_bufptr, "%2d #%4d", &lib, &log_downno);
  460.     len = sprintf(target, "DL%d_%d.lzh", lib, log_downno);
  461.     strcpy(log_downname, (target + (len > 12 ? 2 : 0)));
  462.     strcpy(log_docfile, log_downname);
  463.     strcpy(strchr(log_docfile, '.'), ".GGG");
  464.  
  465. #if 0
  466.     /* 複数フォーラムの可能性がある場合 */
  467.     get_forum_overrun();
  468.  
  469.     fprintf(fpmes, "forum=%s;libno=%d;datano=%d;resp=;docfile=%s;datafile=%s;\n"
  470.         ,log_fname, lib, log_downno, log_docfile, log_downname);
  471. #else
  472.     fprintf(fpmes, "forum=FRAV;libno=%d;datano=%d;resp=;docfile=%s;datafile=%s;\n"
  473.         ,lib, log_downno, log_docfile, log_downname);
  474. #endif
  475.  
  476. }
  477.  
  478.